package it.gestoreContratti.gui.panels;

import it.gestoreContratti.entity.Contratto;
import it.gestoreContratti.entity.Periodo;
import it.gestoreContratti.inputVerifiers.DateInputVerifier;
import it.gestoreContratti.inputVerifiers.NumericInputVerifier;
import it.gestoreContratti.inputVerifiers.StringInputVerifier;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class VisualizzaContrattoPanel extends JPanel {

	private static final long serialVersionUID = 3886760886535183263L;
	private JTextField numeroContrattoTextField;
	private JTextField dittaTextField;
	private JTextField dataInizioTextField;
	private JLabel dataScadenzaLabel;
	private JTextField dataScadenzaTexField;
	private JLabel importoLabel;
	private JTextField importoTextField;
	private JLabel rimanenzaLabel;
	private JTextField rimanenzaTextField;
	private JLabel commentoLabel;
	private JTextArea commentoTextArea;
	private JLabel durataLabel;
	private JComboBox periodoComboBox;
	private JTextField durataTextField;
	private JScrollPane scrollPane;
	private DateFormat dateFormat;
	
	
	
	
	
	public VisualizzaContrattoPanel(Contratto contratto) {		
		dateFormat = new SimpleDateFormat("dd/MM/yyyy");
		setName("nuovo contratto panel");		
		setSize(800, 600);		
		GridBagLayout gbl_this = new GridBagLayout();
		gbl_this.columnWidths = new int[]{179, 87, 0, 0};
		gbl_this.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 112, 0, 0};
		gbl_this.columnWeights = new double[]{0.0, 0.0, 1.0, Double.MIN_VALUE};
		gbl_this.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
		this.setLayout(gbl_this);
		
		JLabel numeroContrattoLabel = new JLabel("Numero Contratto");
		GridBagConstraints gbc_numeroContrattoLabel = new GridBagConstraints();
		gbc_numeroContrattoLabel.insets = new Insets(0, 0, 5, 5);
		gbc_numeroContrattoLabel.anchor = GridBagConstraints.EAST;
		gbc_numeroContrattoLabel.gridx = 0;
		gbc_numeroContrattoLabel.gridy = 0;
		this.add(numeroContrattoLabel, gbc_numeroContrattoLabel);
		
		numeroContrattoTextField = new JTextField();
		numeroContrattoTextField.setText(contratto.getNumero().toString());
		numeroContrattoTextField.setEditable(false);
		GridBagConstraints gbc_numeroContrattoTextField = new GridBagConstraints();
		gbc_numeroContrattoTextField.gridwidth = 2;
		gbc_numeroContrattoTextField.insets = new Insets(0, 0, 5, 0);
		gbc_numeroContrattoTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_numeroContrattoTextField.gridx = 1;
		gbc_numeroContrattoTextField.gridy = 0;
		this.add(numeroContrattoTextField, gbc_numeroContrattoTextField);
		numeroContrattoTextField.setColumns(10);
		numeroContrattoTextField.setInputVerifier(new NumericInputVerifier("Numero Contratto", 15));
		
		JLabel dittaLabel = new JLabel("Ditta");
		GridBagConstraints gbc_dittaLabel = new GridBagConstraints();
		gbc_dittaLabel.anchor = GridBagConstraints.EAST;
		gbc_dittaLabel.insets = new Insets(0, 0, 5, 5);
		gbc_dittaLabel.gridx = 0;
		gbc_dittaLabel.gridy = 1;
		this.add(dittaLabel, gbc_dittaLabel);
		
		dittaTextField = new JTextField();
		dittaTextField.setText(contratto.getDitta());
		dittaTextField.setEditable(false);
		GridBagConstraints gbc_dittaTextField = new GridBagConstraints();
		gbc_dittaTextField.gridwidth = 2;
		gbc_dittaTextField.insets = new Insets(0, 0, 5, 0);
		gbc_dittaTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_dittaTextField.gridx = 1;
		gbc_dittaTextField.gridy = 1;
		this.add(dittaTextField, gbc_dittaTextField);
		dittaTextField.setColumns(10);
		dittaTextField.setInputVerifier(new StringInputVerifier("ditta", 30));
		
		JLabel dataInizioLabel = new JLabel("Data Inizio");
		GridBagConstraints gbc_dataInizioLabel = new GridBagConstraints();
		gbc_dataInizioLabel.anchor = GridBagConstraints.EAST;
		gbc_dataInizioLabel.insets = new Insets(0, 0, 5, 5);
		gbc_dataInizioLabel.gridx = 0;
		gbc_dataInizioLabel.gridy = 2;
		this.add(dataInizioLabel, gbc_dataInizioLabel);
		
		dataInizioTextField = new JTextField();
		dataInizioTextField.setEditable(false);
		dataInizioTextField.setText(dateFormat.format(contratto.getDataInizio()));
		GridBagConstraints gbc_dataInizioTextField = new GridBagConstraints();
		gbc_dataInizioTextField.gridwidth = 2;
		gbc_dataInizioTextField.insets = new Insets(0, 0, 5, 0);
		gbc_dataInizioTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_dataInizioTextField.gridx = 1;
		gbc_dataInizioTextField.gridy = 2;
		this.add(dataInizioTextField, gbc_dataInizioTextField);
		dataInizioTextField.setColumns(10);
		dataInizioTextField.setInputVerifier(new DateInputVerifier("Data Inizio"));
		
		durataLabel = new JLabel("Durata");
		GridBagConstraints gbc_durataLabel = new GridBagConstraints();
		gbc_durataLabel.anchor = GridBagConstraints.EAST;
		gbc_durataLabel.insets = new Insets(0, 0, 5, 5);
		gbc_durataLabel.gridx = 0;
		gbc_durataLabel.gridy = 3;
		this.add(durataLabel, gbc_durataLabel);
		
		periodoComboBox = new JComboBox();
		periodoComboBox.setEnabled(false);
		periodoComboBox.setModel(new DefaultComboBoxModel(Periodo.values()));
		periodoComboBox.setSelectedItem(contratto.getPeriodo());
		
		GridBagConstraints gbc_periodoComboBox = new GridBagConstraints();
		gbc_periodoComboBox.insets = new Insets(0, 0, 5, 5);
		gbc_periodoComboBox.fill = GridBagConstraints.HORIZONTAL;
		gbc_periodoComboBox.gridx = 1;
		gbc_periodoComboBox.gridy = 3;
		this.add(periodoComboBox, gbc_periodoComboBox);
		
		durataTextField = new JTextField();
		durataTextField.setText(contratto.getDurata().toString());
		durataTextField.setEditable(false);
		
		GridBagConstraints gbc_durataTextField = new GridBagConstraints();
		gbc_durataTextField.insets = new Insets(0, 0, 5, 0);
		gbc_durataTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_durataTextField.gridx = 2;
		gbc_durataTextField.gridy = 3;
		this.add(durataTextField, gbc_durataTextField);
		durataTextField.setColumns(10);
		durataTextField.setInputVerifier(new NumericInputVerifier("Durata", 4));
		
		
		dataScadenzaLabel = new JLabel("Data Scadenza");
		GridBagConstraints gbc_dataScadenzaLabel = new GridBagConstraints();
		gbc_dataScadenzaLabel.anchor = GridBagConstraints.EAST;
		gbc_dataScadenzaLabel.insets = new Insets(0, 0, 5, 5);
		gbc_dataScadenzaLabel.gridx = 0;
		gbc_dataScadenzaLabel.gridy = 4;
		this.add(dataScadenzaLabel, gbc_dataScadenzaLabel);
		
		dataScadenzaTexField = new JTextField();
		dataScadenzaTexField.setText(dateFormat.format(contratto.getDataScadenza()));
		dataScadenzaTexField.setEditable(false);
		GridBagConstraints gbc_dataScadenzaTexField = new GridBagConstraints();
		gbc_dataScadenzaTexField.gridwidth = 2;
		gbc_dataScadenzaTexField.insets = new Insets(0, 0, 5, 0);
		gbc_dataScadenzaTexField.fill = GridBagConstraints.HORIZONTAL;
		gbc_dataScadenzaTexField.gridx = 1;
		gbc_dataScadenzaTexField.gridy = 4;
		this.add(dataScadenzaTexField, gbc_dataScadenzaTexField);
		dataScadenzaTexField.setColumns(10);
		
		importoLabel = new JLabel("Importo");
		GridBagConstraints gbc_importoLabel = new GridBagConstraints();
		gbc_importoLabel.anchor = GridBagConstraints.EAST;
		gbc_importoLabel.insets = new Insets(0, 0, 5, 5);
		gbc_importoLabel.gridx = 0;
		gbc_importoLabel.gridy = 5;
		this.add(importoLabel, gbc_importoLabel);
		
		importoTextField = new JTextField();
		importoTextField.setText(contratto.getImporto().toString());		
		importoTextField.setEditable(false);
		
		
		GridBagConstraints gbc_importoTextField = new GridBagConstraints();
		gbc_importoTextField.gridwidth = 2;
		gbc_importoTextField.insets = new Insets(0, 0, 5, 0);
		gbc_importoTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_importoTextField.gridx = 1;
		gbc_importoTextField.gridy = 5;
		this.add(importoTextField, gbc_importoTextField);
		importoTextField.setColumns(10);
		importoTextField.setInputVerifier(new NumericInputVerifier("Importo", 15));
		
		rimanenzaLabel = new JLabel("Rimanenza");
		GridBagConstraints gbc_rimanenzaLabel = new GridBagConstraints();
		gbc_rimanenzaLabel.anchor = GridBagConstraints.EAST;
		gbc_rimanenzaLabel.insets = new Insets(0, 0, 5, 5);
		gbc_rimanenzaLabel.gridx = 0;
		gbc_rimanenzaLabel.gridy = 6;
		this.add(rimanenzaLabel, gbc_rimanenzaLabel);
		
		rimanenzaTextField = new JTextField();
		rimanenzaTextField.setText(contratto.getRimanenza().toString());
		rimanenzaTextField.setEditable(false);
		GridBagConstraints gbc_rimanenzaTextField = new GridBagConstraints();
		gbc_rimanenzaTextField.gridwidth = 2;
		gbc_rimanenzaTextField.insets = new Insets(0, 0, 5, 0);
		gbc_rimanenzaTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_rimanenzaTextField.gridx = 1;
		gbc_rimanenzaTextField.gridy = 6;
		this.add(rimanenzaTextField, gbc_rimanenzaTextField);
		rimanenzaTextField.setColumns(10);
		
		commentoLabel = new JLabel("Commento");		
		GridBagConstraints gbc_commentoLabel = new GridBagConstraints();
		gbc_commentoLabel.anchor = GridBagConstraints.NORTHEAST;
		gbc_commentoLabel.insets = new Insets(0, 0, 5, 5);
		gbc_commentoLabel.gridx = 0;
		gbc_commentoLabel.gridy = 7;
		this.add(commentoLabel, gbc_commentoLabel);
		
		scrollPane = new JScrollPane();
		GridBagConstraints gbc_scrollPane = new GridBagConstraints();
		gbc_scrollPane.fill = GridBagConstraints.BOTH;
		gbc_scrollPane.gridwidth = 2;
		gbc_scrollPane.insets = new Insets(0, 0, 5, 0);
		gbc_scrollPane.gridx = 1;
		gbc_scrollPane.gridy = 7;
		add(scrollPane, gbc_scrollPane);
		
		commentoTextArea = new JTextArea(5, 30);
		commentoTextArea.setText(contratto.getCommento());
		commentoTextArea.setEditable(false);
		scrollPane.setViewportView(commentoTextArea);
		commentoTextArea.setInputVerifier(new StringInputVerifier("Commento", 255));

	}	
	
}



